//
//  LKMapBottomListCell.m
//  LKIntelligentVideoProject
//
//  Created by she1323 on 2018/9/26.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKMapBottomListCell.h"

@interface LKMapBottomListCell()<BMKRouteSearchDelegate>

@end


@implementation LKMapBottomListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setModel:(LKMapPointModel *)model{
    _model = model;
    self.statusLabel.text = @"在线";
    self.statusLabel.textColor = [UIColor blueColor];
    self.titleLabel.text = _model.unitAddr;
    self.timeLabel.hidden = YES;
    if ([model.unitType isEqual:@"1"]) {
        self.timeLabel.hidden = NO;
       self.typeImageView.image = [UIImage imageNamed:@"WechatIMG1"];
    }else if ([model.unitType isEqual:@"2"]){
        if ([model.doorStatus isEqual:@"2"]) {
            self.typeImageView.image = [UIImage imageNamed:@"tapOpenDoor"];
        }else{
           self.typeImageView.image = [UIImage imageNamed:@"tapCloseDoor"];
        }
    }else if([model.unitType isEqual:@"3"]){
        
       self.typeImageView.image = [UIImage imageNamed:@"WechatIMG3"];
    }else{
        self.typeImageView.image = [UIImage imageNamed:@"WechatIMG4"];
    }
    self.distanceLabel.text = _model.distance;
    
    if ([_model.alarmStatus isEqual:@"2"]) {
        self.statusLabel.text = @"正常使用";
        self.statusLabel.textColor = [UIColor blueColor];
        self.timeLabel.text = @"已处理";
    }else if([_model.alarmStatus isEqual:@"0"]){
       self.statusLabel.text = _model.alarmGradeString;
        self.statusLabel.textColor = [UIColor redColor];
        self.typeImageView.image = [UIImage imageNamed:@"jinggai"];
        self.timeLabel.text = @"未处理";
    }else if([_model.alarmStatus isEqual:@"1"]){
        self.statusLabel.text = _model.alarmGradeString;
        self.statusLabel.textColor = [UIColor redColor];
        self.typeImageView.image = [UIImage imageNamed:@"jinggai"];
        self.timeLabel.text = @"处理中";
    }
//    self.timeLabel.text = self.caculateTime;
//    BMKRouteSearch *routeSearch = [[BMKRouteSearch alloc] init];
//    routeSearch.delegate = self;
//    BMKPlanNode *start = [[BMKPlanNode alloc] init];
//    start.pt = _model.curentPt;
//    BMKPlanNode *end = [[BMKPlanNode alloc] init];
//    end.pt = CLLocationCoordinate2DMake([_model.unitLatitude floatValue], [_model.unitLongitude floatValue]);
//    BMKWalkingRoutePlanOption *planOption = [[BMKWalkingRoutePlanOption alloc] init];
//    planOption.from = start;
//    planOption.to = end;
//    BOOL flag = [routeSearch walkingSearch:planOption];
//    if (flag) {
//
//    }else{
//
//    }
}
/**
 *返回步行搜索结果
 *@param searcher 搜索对象
 *@param result 搜索结果，类型为BMKWalkingRouteResult
 *@param error 错误号，@see BMKSearchErrorCode
 */
-(void)onGetWalkingRouteResult:(BMKRouteSearch *)searcher result:(BMKWalkingRouteResult *)result errorCode:(BMKSearchErrorCode)error{
    NSLog(@"onGetWalkingRouteResult error:%d", (int)error);
    if (error == BMK_SEARCH_NO_ERROR) {
        BMKWalkingRouteLine *routineStr = result.routes.firstObject;
        NSLog(@"%@",routineStr.duration);
        NSLog(@"%d%d%d",routineStr.duration.dates,routineStr.duration.hours,routineStr.duration.minutes);
        self.timeLabel.text = [NSString stringWithFormat:@"步行大约%d小时%d分钟",routineStr.duration.hours,routineStr.duration.minutes];
        
        //成功获取结果
    } else {
        //检索失败
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
